<template>

  <el-container>
    <el-header>
          <h1 align="center">我的考试</h1>
    </el-header>
    <el-main>
        <el-table :data="list" style="width: 100%">
              <el-table-column prop="examId" label="编号"></el-table-column>
              <el-table-column prop="examName" label="考试名称"></el-table-column>
              <el-table-column prop="startTime" label="开始时间"></el-table-column>
              <el-table-column prop="endTime" label="截止时间" ></el-table-column>
              <el-table-column label="操作"  >
                  <template slot-scope="scope">
                      <template v-if="scope.row.startTime >curDate">
                         <el-tag>时间未到</el-tag>
                      </template>
                    <template v-else-if="scope.row.endTime < curDate">
                        <el-tag>时间已过</el-tag>
                    </template>
                    <template v-else>
                        <el-button type="success" size="mini" @click="joinExam(scope.row)">参加考试</el-button>
                    </template>

                  </template>
              </el-table-column>
        </el-table>
    </el-main>

  </el-container>
</template>

<script>
    export default {
        name: "MyExam",
        data(){
           return{
              list:[],
              curDate:null//当前时间
           }
        },
        methods:{
             queryMyExam(){//查询我的考试
                  const self = this;
                  this.$http.get("/server-exam-manager/exam/exam")
                  .then(function (rs) {
                        if(rs.data.code==200){
                            self.list = rs.data.data;
                        }

                  })
             },
          joinExam(v){  //参加考试
               localStorage.setItem("examName",v.examName);
              //考试用户主键id
              localStorage.setItem("examUserId",v.examUserId);
               //访问考试页面
              window.open("/curExam");

              //this.$router.replace({"name":"curExam",query:{"examName":v.examName}})
          }

        },
       created() {
            this.queryMyExam();
            const d = new Date();
            const y = d.getFullYear();
            const m = d.getMonth()+1;
            const date = d.getDate();
            const h = d.getHours();
            const mm = d.getMinutes()
            if(m<10 && date<10){
              this.curDate = y+"-0"+m+"-0"+date+" "+h+":"+mm;
            } else if(m<10 && date>10){
              this.curDate = y+"-0"+m+"-"+date+" "+h+":"+mm;
            }else if(m>10 && date<10){
              this.curDate = y+"-"+m+"-0"+date+" "+h+":"+mm;
            }else{
              this.curDate = y+"-"+m+"-"+date+" "+h+":"+mm;
            }
            console.log(this.curDate)
       }

    }
</script>

<style scoped>

</style>
